using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using System;
namespace MicroMsg.Scene
{
	public class NetSceneGetA8Key : NetSceneBaseEx<GetA8KeyReq, GetA8KeyResp, GetA8KeyReq.Builder>
	{
		private const string TAG = "NetSceneGetA8Key";
		private DelegateNavigateToUrl delegateNavigat;
		public bool doScene(string string_0, GetA8KeyScene scene, DelegateNavigateToUrl navigateToUrl = null, GetA8KeyOpCode opCode = GetA8KeyOpCode.MMGETA8KEY_REDIRECT)
		{
			if (string.IsNullOrEmpty(string_0))
			{
				return false;
			}
			this.delegateNavigat = navigateToUrl;
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.A2Key = Util.toSKBuffer(AccountMgr.getCurAccount().bytesA2Key);
			this.mBuilder.OpCode = (uint)opCode;
			this.mBuilder.ReqUrl = Util.toSKString(string_0);
			this.mBuilder.Scene = (uint)scene;
			this.mBuilder.AppID = Util.toSKString("");
			this.mBuilder.Scope = Util.toSKString("");
			this.mBuilder.FriendUserName = "";
			this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/geta8key";
			this.mSessionPack.mConnectMode = 2;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(GetA8KeyReq request, GetA8KeyResp response)
		{
			Log.smethod_1("NetSceneGetA8Key", "send request failed");
			EventCenter.postEvent(EventConst.ON_NETSCENE_GET_A8KEY_ERR, RetConst.MM_ERR_CLIENT, null);
		}
		protected override void onSuccess(GetA8KeyReq request, GetA8KeyResp response)
		{
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneGetA8Key", "send request failed ret =" + ret);
				EventCenter.postEvent(EventConst.ON_NETSCENE_GET_A8KEY_ERR, ret, null);
				return;
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_GET_A8KEY_SUCCESS, new A8KeyInfo
			{
				FullURL = response.FullURL,
				A8Key = response.A8Key,
				ActionCode = response.ActionCode,
				Title = response.Title,
				Content = response.Content
			}, null);
			if (this.delegateNavigat != null)
			{
				this.delegateNavigat(response.FullURL);
			}
		}
	}
}
